﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLTN.Entities;
using DLTN.Data;

public partial class Tour_Controls_ControlTourDocGroupContent : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int TotalRows = 0;
            TList<LoaiTour> TList_LoaiTour = DataRepository.LoaiTourProvider.GetPaged("TenLoaiTour like N'%" + Common.TourDoc + "%'", "ID", 0, 0, out TotalRows);
            if (TList_LoaiTour.Count > 0)
            {
                H_HiddenID.Value = TList_LoaiTour[0].Id.ToString();
                DisplayExplorativeTour(); // Tour thám hiểm
                DisplayHoneyMoonTour();   // Tour trăng mật
                DisplayHighUpTour();      // Tour cao cấp
                DisplaySpecialTour();     // Tour đặc biệt
            }

        }
    }

    // Hiển thị tour thám hiểm (khung đầu tiên)
    private void DisplayExplorativeTour()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";

        TList<SubTour> TList_SubTour = DataRepository.SubTourProvider.GetPaged("IdLoaiTour = " + H_HiddenID.Value + " And TenSubTour like N'%" + Common.ExplorativeTour + "%'", "ID", 0, 0, out TotalRows);
        if (TList_SubTour.Count > 0)
        {
            WhereClause += " and IdSubTour in (select Id from SubTour where Id = " + TList_SubTour[0].Id + " )";
            TList<Tour> TList_Tour = DataRepository.TourProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 5, out TotalRows);

            if (TList_Tour.Count > 0)
            {
                int j = 1;
                //Phần liệt kê
                
                for (int i = 0; i <= TList_Tour.Count - 1; i++)
                {
                    strHTML += "<div id=\"tour-hot-content-" + j + "\">";
                    strHTML += "<div>";
                    strHTML += "<div style=\"float: left; margin-top: 5px;\"><div style=\"float: left; height:33px;\">";
                    strHTML += "<img src=\"images/dltn/caydua.png\"></div>";
                    strHTML += "<div style=\"float: right; margin-left: 5px;\"><div class=\"chumenunhomtour\">";
                    strHTML += "<a href='SubListTour/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(Common.ExplorativeTour) + ".aspx' >" + Common.ExplorativeTour.ToUpper() + "</a></div>";
                    strHTML += "<div class=\"date-time\">" + Common.StandardStringjquery(TList_Tour[i].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'")) + "</div></div></div>";
                    strHTML += "<a href=\"Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx" + "\">";
                    strHTML += "<img class=\"radius\" alt='" + TList_Tour[i].TieuDe + "' src=\"upload/Tour/" + TList_Tour[i].AnhDaiDien + "\" border=\"0\" width=\"300\" height=\"150\"></a></div>";
                    strHTML += "<div style=\"text-align: justify; line-height:150%; height: 89px; font-family: Tahoma; margin-top: 3px\"><span style=\"font-weight: bold; color: red\">";
                    strHTML += "<a class=\"TinTucRight\" href='Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx'>" + TList_Tour[i].TieuDe + "</a></span>: ";
                    strHTML += "</span><br>" + (TList_Tour[i].TomTat.ToString().Length > 250 ? TList_Tour[i].TomTat.Substring(0, 250) + "..." : TList_Tour[i].TomTat.ToString()) + "</div>";
                    strHTML += "<div style=\"margin-top: -5px; padding-left: 207px\"><div class=\"seemoreDiv\">";
                    strHTML += "<a href=\"Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx" + "\" class=\"seemoreText\"><div style=\"padding-top: 2px; padding-left: 2px\">Xem tiếp</div></a>";
                    strHTML += "</div></div></div>";
                    
                    j++;
                }
            }
            else
            {
                strHTML += "<div style=\"float: left; margin-top: 5px;\"><div style=\"float: left\">";
                strHTML += "<img src=\"images/dltn/caydua.png\"></div>";
                strHTML += "<div style=\"float: right; margin-left: 5px;\"><div class=\"chumenunhomtour\">" + Common.ExplorativeTour.ToUpper() + "</div>";
                strHTML += "<div class=\"date-time\"></div></div></div>";
            }
        }

        litExplorativeTour.Text = strHTML;
    }

    // Hiển thị tour trăng mật (khung thứ 2)
    private void DisplayHoneyMoonTour()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";

        TList<SubTour> TList_SubTour = DataRepository.SubTourProvider.GetPaged("IdLoaiTour = " + H_HiddenID.Value + " And TenSubTour like N'%" + Common.HoneyMoonTour + "%'", "ID", 0, 0, out TotalRows);
        if (TList_SubTour.Count > 0)
        {
            WhereClause += " and IdSubTour in (select Id from SubTour where Id = " + TList_SubTour[0].Id + " )";
            TList<Tour> TList_Tour = DataRepository.TourProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 5, out TotalRows);

            if (TList_Tour.Count > 0)
            {
                int j = 1;
                //Phần liệt kê
                
                for (int i = 0; i <= TList_Tour.Count - 1; i++)
                {
                    strHTML += "<div id=\"tour-tn-content-" + j + "\">";
                    strHTML += "<div>";
                    strHTML += "<div style=\"float: left; margin-top: 5px;\"><div style=\"float: left; height:33px;\">";
                    strHTML += "<img src=\"images/dltn/specialTour.png\"></div>";
                    strHTML += "<div style=\"float: right; margin-left: 5px;\"><div class=\"chumenunhomtour\">";
                    strHTML += "<a href='SubListTour/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(Common.HoneyMoonTour) + ".aspx' >" + Common.HoneyMoonTour.ToUpper() + "</a></div>";
                    strHTML += "<div class=\"date-time\">" + Common.StandardStringjquery(TList_Tour[i].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'")) + "</div></div></div>";
                    strHTML += "<a href=\"Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx" + "\">";
                    strHTML += "<img class=\"radius\" alt='" + TList_Tour[i].TieuDe + "' src=\"upload/Tour/" + TList_Tour[i].AnhDaiDien + "\" border=\"0\" width=\"300\" height=\"150\"></a></div>";
                    strHTML += "<div style=\"text-align: justify; line-height:150%; height: 89px; font-family: Tahoma; margin-top: 3px\"><span style=\"font-weight: bold; color: red\">";
                    strHTML += "<a class=\"TinTucRight\" href='Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx'>" + TList_Tour[i].TieuDe + "</a></span>: ";
                    strHTML += "</span><br>" + (TList_Tour[i].TomTat.ToString().Length > 250 ? TList_Tour[i].TomTat.Substring(0, 250) + "..." : TList_Tour[i].TomTat.ToString()) + "</div>";
                    strHTML += "<div style=\"margin-top: -5px; padding-left: 207px\"><div class=\"seemoreDiv\">";
                    strHTML += "<a href=\"Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx" + "\" class=\"seemoreText\"><div style=\"padding-top: 2px; padding-left: 2px\">Xem tiếp</div></a>";
                    strHTML += "</div></div></div>";
                    
                    j++;
                }
            }
            else
            {
                strHTML += "<div style=\"float: left; margin-top: 5px;\"><div style=\"float: left\">";
                strHTML += "<img src=\"images/dltn/specialTour.png\"></div>";
                strHTML += "<div style=\"float: right; margin-left: 5px;\"><div class=\"chumenunhomtour\">" + Common.HoneyMoonTour.ToUpper() + "</div>";
                strHTML += "<div class=\"date-time\"></div></div></div>";
            }
        }

        litHoneyMoonTour.Text = strHTML;
    }

    // Hiển thị tour cao cấp (khung thứ 3)
    private void DisplayHighUpTour()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";

        TList<SubTour> TList_SubTour = DataRepository.SubTourProvider.GetPaged("IdLoaiTour = " + H_HiddenID.Value + " And TenSubTour like N'%" + Common.HighUpTour + "%'", "ID", 0, 0, out TotalRows);
        if (TList_SubTour.Count > 0)
        {
            WhereClause += " and IdSubTour in (select Id from SubTour where Id = " + TList_SubTour[0].Id + " )";
            TList<Tour> TList_Tour = DataRepository.TourProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 5, out TotalRows);

            if (TList_Tour.Count > 0)
            {
                int j = 1;
                //Phần liệt kê
                
                for (int i = 0; i <= TList_Tour.Count - 1; i++)
                {
                    strHTML += "<div id=\"tour-doc-content-" + j + "\">";
                    strHTML += "<div>";
                    strHTML += "<div style=\"float: left; margin-top: 5px;\"><div style=\"float: left; height:33px;\">";
                    strHTML += "<img src=\"images/dltn/internationTour.png\"></div>";
                    strHTML += "<div style=\"float: right; margin-left: 5px;\"><div class=\"chumenunhomtour\">";
                    strHTML += "<a href='SubListTour/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(Common.HighUpTour) + ".aspx' >" + Common.HighUpTour.ToUpper() + "</a></div>";
                    strHTML += "<div class=\"date-time\">" + Common.StandardStringjquery(TList_Tour[i].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'")) + "</div></div></div>";
                    strHTML += "<a href=\"Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx" + "\">";
                    strHTML += "<img class=\"radius\" alt='" + TList_Tour[i].TieuDe + "' src=\"upload/Tour/" + TList_Tour[i].AnhDaiDien + "\" border=\"0\" width=\"300\" height=\"150\"></a></div>";
                    strHTML += "<div style=\"text-align: justify; line-height:150%; height: 89px; font-family: Tahoma; margin-top: 3px\"><span style=\"font-weight: bold; color: red\">";
                    strHTML += "<a class=\"TinTucRight\" href='Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx'>" + TList_Tour[i].TieuDe + "</a></span>: ";
                    strHTML += "</span><br>" + (TList_Tour[i].TomTat.ToString().Length > 250 ? TList_Tour[i].TomTat.Substring(0, 250) + "..." : TList_Tour[i].TomTat.ToString()) + "</div>";
                    strHTML += "<div style=\"margin-top: -5px; padding-left: 207px\"><div class=\"seemoreDiv\">";
                    strHTML += "<a href=\"Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx" + "\" class=\"seemoreText\"><div style=\"padding-top: 2px; padding-left: 2px\">Xem tiếp</div></a>";
                    strHTML += "</div></div></div>";
                    
                    j++;
                }
            }
            else
            {
                strHTML += "<div style=\"float: left; margin-top: 5px;\"><div style=\"float: left\">";
                strHTML += "<img src=\"images/dltn/internationTour.png\"></div>";
                strHTML += "<div style=\"float: right; margin-left: 5px;\"><div class=\"chumenunhomtour\">" + Common.HighUpTour.ToUpper() + "</div>";
                strHTML += "<div class=\"date-time\"></div></div></div>";
            }
        }

        litHighUpTour.Text = strHTML;
    }

    // Hiển thị tour đặt biệt (khung thứ 4)
    private void DisplaySpecialTour()
    {
        string strHTML = "";
        int TotalRows = 0;
        string WhereClause = "1=1";
        TList<SubTour> TList_SubTour = DataRepository.SubTourProvider.GetPaged("IdLoaiTour = " + H_HiddenID.Value + " And TenSubTour like N'%" + Common.TourDacBiet + "%'", "ID", 0, 0, out TotalRows);
        if (TList_SubTour.Count > 0)
        {
            WhereClause += " and IdSubTour in (select Id from SubTour where Id = " + TList_SubTour[0].Id + " )";
            TList<Tour> TList_Tour = DataRepository.TourProvider.GetPaged(WhereClause, "NgayCapNhat DESC", 0, 5, out TotalRows);

            if (TList_Tour.Count > 0)
            {
                int j = 1;
                //Phần liệt kê
                
                for (int i = 0; i <= TList_Tour.Count - 1; i++)
                {
                    strHTML += "<div id=\"tour-ng-content-" + j + "\">";
                    strHTML += "<div>";
                    strHTML += "<div style=\"float: left; margin-top: 5px;\"><div style=\"float: left; height:33px;\">";
                    strHTML += "<img src=\"images/dltn/caydu.png\"></div>";
                    strHTML += "<div style=\"float: right; margin-left: 5px;\"><div class=\"chumenunhomtour\">";
                    strHTML += "<a href='SubListTour/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(Common.TourDacBiet) + ".aspx' >" + Common.TourDacBiet.ToUpper() + "</a></div>";
                    strHTML += "<div class=\"date-time\">" + Common.StandardStringjquery(TList_Tour[i].NgayCapNhat.ToString("''dd/MM/yyyy, HH:mm 'GMT+7'")) + "</div></div></div>";
                    strHTML += "<a href=\"Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx" + "\">";
                    strHTML += "<img class=\"radius\" alt='" + TList_Tour[i].TieuDe + "' src=\"upload/Tour/" + TList_Tour[i].AnhDaiDien + "\" border=\"0\" width=\"300\" height=\"150\"></a></div>";
                    strHTML += "<div style=\"text-align: justify; line-height:150%; height: 89px; font-family: Tahoma; margin-top: 3px\"><span style=\"font-weight: bold; color: red\">";
                    strHTML += "<a class=\"TinTucRight\" href='Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx'>" + TList_Tour[i].TieuDe + "</a></span>: ";
                    strHTML += "</span><br>" + (TList_Tour[i].TomTat.ToString().Length > 250 ? TList_Tour[i].TomTat.Substring(0, 250) + "..." : TList_Tour[i].TomTat.ToString()) + "</div>";
                    strHTML += "<div style=\"margin-top: -5px; padding-left: 207px\"><div class=\"seemoreDiv\">";
                    strHTML += "<a href=\"Tour/" + TList_Tour[i].Id + "/" + TList_Tour[i].IdSubTour + "/" + GetTieuDe(TList_Tour[i].TieuDe) + ".aspx" + "\" class=\"seemoreText\"><div style=\"padding-top: 2px; padding-left: 2px\">Xem tiếp</div></a>";
                    strHTML += "</div></div></div>";
                    
                    j++;
                }
            }
            else
            {
                strHTML += "<div style=\"float: left; margin-top: 5px;\"><div style=\"float: left\">";
                strHTML += "<img src=\"images/dltn/caydu.png\"></div>";
                strHTML += "<div style=\"float: right; margin-left: 5px;\"><div class=\"chumenunhomtour\">" + Common.TourDacBiet.ToUpper() + "</div>";
                strHTML += "<div class=\"date-time\"></div></div></div>";
            }
        }

        litSpecialTour.Text = strHTML;
    }

    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }
}